<template>
  <div class="list-page-container">
    <a-card>
      <a-form layout="inline" @keyup.enter.native="handleSearch">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <CompositeSearch
              :fieldList="fieldList"
              @getParams="getSearchValue"
              @adSearch="onAdSearch"
              @adClear="onAdClear"
              @tagClick="onTagClick">
              <template v-slot:ad-search-content>
                <a-form-model
                  ref="adSearchFormRef"
                  :model="adSearchFormData"
                  layout="vertical">
                  <a-row :gutter="24">
                    <a-col :span="24">
                      <a-form-model-item label="创建时间">
                        <a-range-picker
                          v-model="createTime"
                          format="YYYY-MM-DD"
                          style="width:100%;"
                          @change="(timeRange, timeStringRange) => setTimeRange('createTimeStart', 'createTimeEnd', timeRange, timeStringRange)"/>
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                </a-form-model>
              </template>
            </CompositeSearch>
          </a-col>
          <a-col :md="18" :sm="24">
            <div class="space-btn">
              <a-button type="primary" icon="plus" @click="onAdd">添加</a-button>
              <a-button @click="onExport">导出</a-button>
              <a-button type="danger" @click="onDelete">删除</a-button>
            </div>
          </a-col>
        </a-row>
      </a-form>
      <a-table
        ref="table"
        rowKey="id"
        size="middle"
        bordered
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :row-selection="{ fixed: true, selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        :scroll="{ x: '100%', autoHeight: true }"
        :pagination="pagination">
        <span slot="date" slot-scope="text">{{ text | DateFormat }}</span>
        <template slot="examineTime" slot-scope="text, record">
          <span>{{ record.examineTimeStart }}</span>
          至
          <span>{{ record.examineTimeEnd }}</span>
        </template>
        <template slot="action" slot-scope="text, record">
          <span class="cus-text" pointer @click="onEdit(record)">编辑</span>
          <span class="cus-text" pointer @click="onCheck(record)">查看</span>
        </template>
      </a-table>
    </a-card>

    <!-- 创建绩效考核 -->
    <PerformaceExamineCreate ref="PerformaceExamineCreate" @successCallback="handleSearch" />
    <!-- 绩效考核详情 -->
    <PerformaceExamineDetail ref="PerformaceExamineDetail" />
  </div>
</template>

<script>
import ListPageMixin from '@/mixins/ListPageMixin.js';
import optionsMixin from '@views/supplier-manage/performace-examine/optionsMixin.js'
import PerformaceExamineCreate from '@views/supplier-manage/performace-examine/components/Create.vue'
import PerformaceExamineDetail from '@views/supplier-manage/performace-examine/detail.vue'

export default {
  name: 'PerformaceExamineIndex',
  mixins: [ ListPageMixin, optionsMixin ],
  components: {
    PerformaceExamineCreate,
    PerformaceExamineDetail
  },
  data() {
    return {
      adSearchFormData: {
        createTimeStart: '',
        createTimeEnd: '',
      },
      createTime: [],
      dataSource: [],
      originalDataSource: [
        {
          examineTimeStart: '2023-01-01',
          examineTimeEnd: '2023-12-31',
          examineCategory: '传感器品类',
          examineName: '2024年度供应商考核-传感器',
          examineCode: 'JX20241208001',
          createTime: '2024-06-08 11:08:30',
          examineNum: '100',
          examineWaitNum: '20',
          examineAlreadyNum: '80',
          aLevel: '60',
          bLevel: '10',
          cLevel: '8',
          dLevel: '2',
        },
        {
          examineTimeStart: '2023-01-01',
          examineTimeEnd: '2023-12-31',
          examineCategory: '传感器品类',
          examineName: '2024年度供应商考核-传感器',
          examineCode: 'JX20241208001',
          createTime: '2024-06-08 11:08:30',
          examineNum: '100',
          examineWaitNum: '10',
          examineAlreadyNum: '90',
          aLevel: '70',
          bLevel: '10',
          cLevel: '8',
          dLevel: '2',
        },
        {
          examineTimeStart: '2023-01-01',
          examineTimeEnd: '2023-12-31',
          examineCategory: '传感器品类',
          examineName: '2024年度供应商考核-传感器',
          examineCode: 'JX20241208001',
          createTime: '2024-06-08 11:08:30',
          examineNum: '100',
          examineWaitNum: '0',
          examineAlreadyNum: '100',
          aLevel: '80',
          bLevel: '10',
          cLevel: '8',
          dLevel: '2',
        },
        {
          examineTimeStart: '2023-01-01',
          examineTimeEnd: '2023-12-31',
          examineCategory: '传感器品类',
          examineName: '2024年度供应商考核-传感器',
          examineCode: 'JX20241208001',
          createTime: '2024-06-08 11:08:30',
          examineNum: '100',
          examineWaitNum: '0',
          examineAlreadyNum: '100',
          aLevel: '80',
          bLevel: '10',
          cLevel: '8',
          dLevel: '2',
        },
        {
          examineTimeStart: '2023-01-01',
          examineTimeEnd: '2023-12-31',
          examineCategory: '传感器品类',
          examineName: '2024年度供应商考核-传感器',
          examineCode: 'JX20241208001',
          createTime: '2024-06-08 11:08:30',
          examineNum: '100',
          examineWaitNum: '0',
          examineAlreadyNum: '100',
          aLevel: '80',
          bLevel: '10',
          cLevel: '8',
          dLevel: '2',
        },
        {
          examineTimeStart: '2023-01-01',
          examineTimeEnd: '2023-12-31',
          examineCategory: '传感器品类',
          examineName: '2024年度供应商考核-传感器',
          examineCode: 'JX20241208001',
          createTime: '2024-06-08 11:08:30',
          examineNum: '100',
          examineWaitNum: '0',
          examineAlreadyNum: '100',
          aLevel: '80',
          bLevel: '10',
          cLevel: '8',
          dLevel: '2',
        },
        {
          examineTimeStart: '2023-01-01',
          examineTimeEnd: '2023-12-31',
          examineCategory: '传感器品类',
          examineName: '2024年度供应商考核-传感器',
          examineCode: 'JX20241208001',
          createTime: '2024-06-08 11:08:30',
          examineNum: '100',
          examineWaitNum: '0',
          examineAlreadyNum: '100',
          aLevel: '80',
          bLevel: '10',
          cLevel: '8',
          dLevel: '2',
        },
        {
          examineTimeStart: '2023-01-01',
          examineTimeEnd: '2023-12-31',
          examineCategory: '传感器品类',
          examineName: '2024年度供应商考核-传感器',
          examineCode: 'JX20241208001',
          createTime: '2024-06-08 11:08:30',
          examineNum: '100',
          examineWaitNum: '0',
          examineAlreadyNum: '100',
          aLevel: '80',
          bLevel: '10',
          cLevel: '8',
          dLevel: '2',
        },
        {
          examineTimeStart: '2023-01-01',
          examineTimeEnd: '2023-12-31',
          examineCategory: '传感器品类',
          examineName: '2024年度供应商考核-传感器',
          examineCode: 'JX20241208001',
          createTime: '2024-06-08 11:08:30',
          examineNum: '100',
          examineWaitNum: '0',
          examineAlreadyNum: '100',
          aLevel: '80',
          bLevel: '10',
          cLevel: '8',
          dLevel: '2',
        },
        {
          examineTimeStart: '2023-01-01',
          examineTimeEnd: '2023-12-31',
          examineCategory: '传感器品类',
          examineName: '2024年度供应商考核-传感器',
          examineCode: 'JX20241208001',
          createTime: '2024-06-08 11:08:30',
          examineNum: '100',
          examineWaitNum: '0',
          examineAlreadyNum: '100',
          aLevel: '80',
          bLevel: '10',
          cLevel: '8',
          dLevel: '2',
        },
      ]
    }
  },
  created() {
    this.handleSearch();
  },
  methods: {
    // 获取 搜索框参数
    getSearchValue(currentValue, selectFiledList) {
      console.log(currentValue, selectFiledList, 'getSearchValue');
      this.handleSearch();
    },
    // 确定搜索 高级搜索
    onAdSearch() {
      console.log(this.adSearchFormData, '确定搜索 高级搜索');
      this.handleSearch();
    },
    // 重置 高级搜索
    onAdClear() {
      console.log('重置 高级搜索');
    },
    onTagClick(data) {
      console.log(data, 'onTagClick');
      const { name } = data;
      if (['筛选组合01', '筛选组合02', '筛选组合03'].includes(name)) {
        this.adSearchFormData.supplierStatus = '1';
        this.adSearchFormData.approveStatus = '1';
      } else if (['筛选组合04', '筛选组合05', '筛选组合06'].includes(name)) {
        this.adSearchFormData.supplierStatus = '2';
        this.adSearchFormData.approveStatus = '2';
      } else {
        this.adSearchFormData.supplierStatus = '3';
        this.adSearchFormData.approveStatus = '3';
      }
    },
    handleSearch() {
      this.loading = true;
      setTimeout(() => {
        this.loading = false;
        this.onSelectClear();
        this.dataSource = this.originalDataSource
      }, 100)
    },
    // 添加
    onAdd() {
      this.$refs.PerformaceExamineCreate.onDrawerOpen();
    },
    // 导出
    onExport() {

    },
    // 删除
    onDelete() {
      console.log(this.selectedRowKeys, this.selectedRows, 'onDelete');
      if (this.selectedRowKeys.length) {
        this.$confirm({
          title: '批量删除',
          content: '确认批量删除？',
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            this.handleSearch();
            this.$message.success(`批量删除成功`);
          }
        });
      } else {
        this.$message.error(`请选择数据！`);
      }
    },
    onEdit() {
      this.$refs.PerformaceExamineDetail.open({ isLook: false });
    },
    onCheck() {
      this.$refs.PerformaceExamineDetail.open({ isLook: true });
    },
  }
}
</script>

<style lang="less" scoped>
</style>